{% extends 'index.html' %}
{% block custome_css %}

{% endblock %}
{% block sidebar %}{% endblock %}

{% block content %}
    <form class="form-horizontal" role="form" method="post">
        {% csrf_token %}
            {% for field in form_obj %}
            <div class="form-group">
                <label for="" class="col-sm-2 control-label">
                    {{ field.label }}
                </label>
                <div class="col-md-8 col-sm-8">
                    {{ field }}
                    {% for error_data in field.errors.get_json_data %}
                        <span style="color: red; margin-right: 5px">{{ error_data.message }};</span>
                    {% endfor %}
                </div>
            </div>
        {% endfor %}

        <div class="row">
            <div class="col-md-3 col-sm-3 col-sm-offset-3 " style="color: red">{{ form_obj.non_field_errors.0 }}</div>
        </div>

        <a href="{% url 'submodul2host_preview' project.id submodul.id %}" class="btn btn-info col-sm-offset-1">取消并返回</a>
        <button type="submit" class="btn btn-success col-sm-offset-7 " >保存</button>
    </form>

{% endblock %}


{% block custome_js %}
    <script>
        $(function () {
            $('[name="is_customize"]').bootstrapSwitch({onText:"是",
                offText:"否",
                onColor:"success",
                offColor:"info"});
            if($('[name="is_customize"]').prop('checked')){
                // 根据后端传回的数据初始化开关状态
                $('[name="is_customize"]').prop('checked',false);
                $('[name="is_customize"]').bootstrapSwitch('state','true')
                $('.customize').removeAttr('disabled');
            }
            $('[name="is_customize"]').on('switchChange.bootstrapSwitch', function (event,state) {
                if(state){
                    $('.customize').removeAttr('disabled');
                }else{
                    $('.customize').attr('disabled','disabled');
                }
            });
        })
    </script>
{% endblock %}